package com.woniuxy.book87.result;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Result<T>{
    private int code ;
    private String message ;
    private T data ;

    private static <T> Result<T> common(int code,String message,T data){
        return new Result<>(code,message,data);
    }

    public static <T> Result<T> ok(){
        return common(200, "操作成功",null);
    }

    public static <T> Result<T> ok(T data){
        return common(200,"操作成功",data);
    }

    public static <T> Result<T> fail(){
        return common(500, "操作失败",null);
    }
    public static <T> Result<T> ok(String message,T data){
        return common(200,message,data);
    }

    public static <T> Result<T> ok(String message){
        return common(200,message,null);
    }

    public static <T> Result<T> fail(String message){
        return common(500,message,null);
    }

    public static <T> Result<T> fail(T data){
        return common(500, "操作失败",data);
    }

    public static <T> Result<T> fail(String message,T data){
        return common(500,message,data);
    }
    public static <T> Result<T> fail(int code,String message){
        return common(code, message,null);
    }
}
